package com.open.exam.mapper;

import com.open.exam.databasemodel.ExamSite;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author naicha
 * Created on 2017/11/7.
 */
@Mapper
public interface ExamSiteMapper {

    @Select("SELECT * FROM ExamSite")
    List<ExamSite> findAllExamSite();

    @Insert("INSERT INTO examsite (\n" +
            "\tExamSiteID,\n" +
            "\tExamSiteName,\n" +
            "\tExamSiteCode\n" +
            ") SELECT\n" +
            "\t#{examSiteID},\n" +
            "\t#{examSiteName},\n" +
            "\t#{examSiteCode}\n" +
            "FROM\n" +
            "\tDUAL\n" +
            "WHERE\n" +
            "\tNOT EXISTS (\n" +
            "\t\tSELECT\n" +
            "\t\t\t1\n" +
            "\t\tFROM\n" +
            "\t\t\tExamSite\n" +
            "\t\tWHERE\n" +
            "\t\t\tExamSiteID = #{examSiteID}\n" +
            "\t)")
    Integer insertExamSite(ExamSite examSite);

    @Update("UPDATE ExamSite SET ExamSiteName = #{examSiteName},ExamSiteCode = #{examSiteCode},SitePwd = #{sitePwd} WHERE ExamSiteID = #{examSiteID}")
    Integer updateExamSite(ExamSite examSite);


}
